///我的设备
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/route_manager.dart';
import 'package:smart_shoes/define/define_colors.dart';
import 'package:smart_shoes/tools/widget_tools.dart';

class MyDevice extends StatefulWidget {
  const MyDevice({super.key});

  @override
  State<MyDevice> createState() => _MyDeviceState();
}

class _MyDeviceState extends State<MyDevice> {
  // tab 索引
  int tabIndex = 0;

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2, // 标签页数量
      child: Scaffold(
        backgroundColor: CustomColors.backgroundColor,
        appBar: AppBar(
          title: const Text('设备'),
          // 将 TabBar 放置在 AppBar 的底部
          bottom: TabBar(
            tabs: const [Tab(text: "我的设备"), Tab(text: "分享我的")],
            onTap: (index) {
              setState(() {
                tabIndex = index;
              });
            },
          ),
        ),
        body: TabBarView(children: [_deviceListView(), _shareMine()]),
      ),
    );
  }

  //我的设备
  Widget _deviceListView() {
    //  ListView.builder(
    //         itemBuilder: (context, index) {
    //           return _deviceItemView();
    //         },
    //         itemCount: 10,
    //       ),
    //     );

    return Container(
      color: CustomColors.backgroundColor,
      child: ListView.builder(
        itemBuilder: (context, index) {
          return _deviceItemView();
        },
        itemCount: 10,
      ),
    );
  }

  Widget _deviceItemView() {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8), // 设置圆角半径为 10
      ),
      margin: EdgeInsets.only(top: 8, left: 12.5, right: 12.5),
      padding: EdgeInsets.only(left: 11.5, right: 11.5, top: 8),
      height: 132.5,
      width: double.infinity,
      child: Column(
        children: [
          //上半部分设备信息
          _deviceInfo(),
          SizedBox(height: 10),
          _option(),
          //下班部分操作按钮
        ],
      ),
    );
  }

  Widget _deviceInfo() {
    return Row(
      children: [
        //设备图片
        //设备信息
        _buildDeviceImage(),
        SizedBox(width: 12),
        Expanded(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                "李文翰",
                style: const TextStyle(
                  fontSize: 14,
                  color: CustomColors.textColor,
                ),
              ),

              _row('设备编号：', "2341343245"),
              _row('绑定时间：', "2025-03-21 11:32:04"),
            ],
          ),
        ),
        //设备状态
        Text(
          "开启中",
          style: const TextStyle(fontSize: 12, color: CustomColors.statusColor),
        ),
      ],
    );
  }

  Widget _row(String title, String content) {
    return Row(
      children: [
        Text(
          title,
          style: const TextStyle(
            fontSize: 13,
            color: CustomColors.uncheckedColor,
          ),
        ),
        Expanded(
          child: Text(
            content,
            style: const TextStyle(fontSize: 13, color: CustomColors.textColor),
          ),
        ),
      ],
    );
  }

  Widget _shareDeviceInfo() {
    return Row(
      children: [
        //设备图片
        //设备信息
        _buildDeviceImage(),
        SizedBox(width: 12),
        Expanded(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                "李文翰",
                style: const TextStyle(
                  fontSize: 14,
                  color: CustomColors.textColor,
                ),
              ),

              _row('设备编号：', "2341343245"),
              _row('绑定时间：', "2025-03-21 11:32:04"),
              _row('分享账号：', "24757337183"),
            ],
          ),
        ),
        //设备状态
        Text(
          "开启中",
          style: const TextStyle(fontSize: 12, color: CustomColors.statusColor),
        ),
      ],
    );
  }

  Widget _buildDeviceImage() {
    return Container(
      width: 57,
      height: 57,
      child: Image.asset(
        'assets/images/yundongxie.png',
        width: 40.49,
        height: 23,
        fit: BoxFit.fitWidth,
      ),
    );
  }

  //double buttonWidth,
  // String title,
  // buttonAction, {
  // Color? bgColor,
  // Color? textColor,
  // double borderWidth = 0.0,
  // Color? borderColor,
  // double radius = 0.0,
  // double fontSize = 15,
  // FontWeight? fontWeight,
  // double height = 49,
  // BoxShadow? shadow,
  // Widget _option() {
  //   // CustomColors.textColor
  //   return Row(
  //     children: [
  //       Expanded(child: SizedBox(width: 10)),

  //       SizedBox(width: 12),
  //       WidgetTools().createCustomInkWellButton(
  //         "撤销分享",
  //         () {},
  //         textColor: CustomColors.textColor,
  //         buttonWidth: 68,
  //         height: 26,
  //         radius: 12.5,
  //         borderColor: CustomColors.textColor,
  //         borderWidth: 1,
  //         shadow: BoxShadow(),
  //         fontSize: 12,
  //         bgColor: Colors.white,
  //       ),

  //       ///
  //     ],
  //   );
  // }

  Widget _option() {
    // CustomColors.textColor
    return Row(
      children: [
        Expanded(child: SizedBox(width: 10)),
        WidgetTools().createCustomInkWellButton(
          "删除",
          () {},
          textColor: CustomColors.redColor,
          buttonWidth: 68,
          height: 26,
          radius: 12.5,
          borderColor: CustomColors.redColor,
          borderWidth: 1,
          shadow: BoxShadow(),
          bgColor: Colors.white,
        ),
        SizedBox(width: 12),
        WidgetTools().createCustomInkWellButton(
          "分享",
          () {},
          textColor: CustomColors.textColor,
          buttonWidth: 68,
          height: 26,
          radius: 12.5,
          borderColor: CustomColors.textColor,
          borderWidth: 1,
          shadow: BoxShadow(),
          bgColor: Colors.white,
        ),

        ///
      ],
    );
  }

  Widget _shareItemView() {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8), // 设置圆角半径为 10
      ),
      margin: EdgeInsets.only(top: 8, left: 12.5, right: 12.5),
      padding: EdgeInsets.only(left: 11.5, right: 11.5, top: 8),
      height: 132.5,
      width: double.infinity,
      child: Column(
        children: [
          //上半部分设备信息
          _shareDeviceInfo(),
          SizedBox(height: 10),
          // _shareOption(),
          //下班部分操作按钮
        ],
      ),
    );
  }

  //分享我的
  Widget _shareMine() {
    return Container(
      color: CustomColors.backgroundColor,
      child: ListView.builder(
        itemBuilder: (context, index) {
          return _shareItemView();
        },
        itemCount: 10,
      ),
    );
  }
}
